package com.tcat.count.web;


import com.google.common.collect.Ordering;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.tcat.common.vo.Count;
import com.tcat.count.client.*;
import com.tcat.count.pojo.Stock;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("count")
@Api(tags = "统计管理")
@DefaultProperties(defaultFallback = "queryUsersFallback")
public class CountController {
    @Autowired
    private UserClient userClient;

    @Autowired
    private OrderClient orderClient;

    @Autowired
    private BrandClient brandClient;

    @Autowired
    private SkuClient skuClient;
    @Autowired
    private StockClient stockClient;
    @ApiOperation(value = "统计用户人数")
    @GetMapping("/member/countUsers")
    public int queryUser(){
        return userClient.queryUsers();
    }

    @ApiOperation(value = "统计商品品牌数")
    @GetMapping("/brand/countBrands")
    public int queryBrand(){
        return brandClient.queryBrands();
    }

    @ApiOperation(value = "统计订单数")
    @GetMapping("/order/countOrders")
    public int queryOrder(){
        return orderClient.queryOrders();
    }

    @ApiOperation(value = "统计sku数")
    @GetMapping("/spec/countSkus")
    public int querySku(){
        return skuClient.querySkus();
    }

    @GetMapping("{id}")
    public Stock queryStock(@PathVariable("id") Long id){
        return stockClient.queryStock(id);
    }
    @ApiOperation(value = "统计")
    @GetMapping
    public Count queryAll(){
        int CountUser=queryUser();
        int CountBrand=queryBrand();
        int CountOrder=queryOrder();
        int CountSku=querySku();
        Count count=new Count(CountUser,CountOrder,CountBrand,CountSku);
        return count;
    }
    public String queryUsersFallback(){
        return "服务器太忙";
    }

    public String queryUsersFallback(Long id){
        return "服务器太忙";
    }

}
